package com.qzsoft.zhjd.laboratory.modules.asphaltSofteningPoint.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.common.utils.ZhjdIotUtils;
import com.qzsoft.zhjd.laboratory.modules.asphaltSofteningPoint.entity.AsphaltSofteningPointEntity;
import com.qzsoft.zhjd.laboratory.modules.asphaltSofteningPoint.entity.AsphaltSofteningPointResEntity;
import com.qzsoft.zhjd.laboratory.modules.asphaltSofteningPoint.service.AsphaltSofteningPointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 沥青软化点试验仪
 *
 * @author sx
 * @email 
 * @date 2023-07-11 18:29:54
 */
@RestController
@RequestMapping("laboratory/asphaltSofteningPoint")
public class AsphaltSofteningPointController {

    @Autowired
    private AsphaltSofteningPointService asphaltSofteningPointService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:page")
    public Result page(@RequestParam Map<String, Object> params){
        IPage page = asphaltSofteningPointService.queryPage(params);
        return ResultUtils.ok(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:find")
    public Result find(@PathVariable("id") String id){
		AsphaltSofteningPointEntity asphaltSofteningPoint = asphaltSofteningPointService.getInfo(id);
        return ResultUtils.ok(asphaltSofteningPoint);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:save")
    public Result save(@RequestBody AsphaltSofteningPointEntity asphaltSofteningPoint){
		asphaltSofteningPointService.saveData(asphaltSofteningPoint);
        return ResultUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:update")
    public Result update(@RequestBody AsphaltSofteningPointEntity asphaltSofteningPoint){
        asphaltSofteningPointService.updateData(asphaltSofteningPoint);
        return ResultUtils.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:delete")
    public Result deleteOne(@PathVariable("id") String id){
        asphaltSofteningPointService.deleteOneData(id);
        return ResultUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:delete")
    public Result delete(@RequestBody String[] ids){
        asphaltSofteningPointService.deleteData(Arrays.asList(ids));
        return ResultUtils.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public Result parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltSofteningPointService.parsingData(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }



    /**
     * 解析上海昌吉沥青软化点数据
     * @param deviceId
     * @param
     * @return
     */
    @PostMapping("/parsingCJData/{deviceId}")
    public Result parsingCJData(@PathVariable("deviceId") String deviceId,@RequestBody byte[] rawData){
        asphaltSofteningPointService.parsingCJData(rawData,deviceId);
        return ResultUtils.ok();
    }


    /**
     * 解析数据
     * @param deviceId
     * @return
     */
    @PostMapping("/reParsingData/{deviceId}")
    public Result reParsingData(@PathVariable("deviceId") String deviceId){
        asphaltSofteningPointService.reParsingData(deviceId);
        return ResultUtils.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingDataTwob/{deviceId}")
    public Result parsingDataTwob(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltSofteningPointService.parsingDataTwob(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }

    /**
     * 绑定材料
     */
    @RequestMapping("/changeSample")
    @RequiresPermissions("laboratory:asphaltSofteningPoint:changeSample")
    public Result changeSample(@RequestBody AsphaltSofteningPointResEntity asphaltSofteningPointRes){
        asphaltSofteningPointService.changeSample(asphaltSofteningPointRes);
        return ResultUtils.ok();
    }
}
